<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';
    protected $frontendNamespace = 'App\Http\Controllers\Frontend';
    protected $backendNamespace = 'App\Http\Controllers\Backend';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //

        parent::boot();

        Route::model('type',\App\Type::class);
        Route::model('photo',\App\Photo::class);
        Route::model('video',\App\Video::class);
        Route::model('feedback',\App\Feedback::class);
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();

        $this->mapFrontendRoutes();
        $this->mapBackendRoutes();

        //
    }

    protected function mapFrontendRoutes()
    {
        Route::middleware('web')
            ->namespace($this->frontendNamespace)
            ->group(base_path('routes/frontend.php'));
    }

    protected function mapBackendRoutes()
    {
        Route::middleware('web')
            ->prefix('admin')
            ->namespace($this->backendNamespace)
            ->group(base_path('routes/backend.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}
